package cn.shyouchi.wuguanjia.android.ui.event.check;

import android.text.TextUtils;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.shyouchi.wuguanjia.android.R;

/**
 * Created by Eenie on 2016/11/3 at 14:40
 * Email: 472279981@qq.com
 * Des:
 */

public class EventCheckAdapter extends BaseQuickAdapter<EventCheckModel,BaseViewHolder> {
    EventCheckContract.View mView;


    public EventCheckAdapter(List<EventCheckModel> data, EventCheckContract.View view) {
        super(R.layout.item_event_check, data);
        this.mView = view;
    }

    @Override
    protected void convert(final BaseViewHolder holder, final EventCheckModel model) {
        holder.setText(R.id.model_name, model.getName());
        holder.setText(R.id.tv_holder_name, model.getValue());
        SeekBar seekBar = holder.getView(R.id.model_range);

        if (model.getType() == EventCheckModel.EVENT_CHECK_TYPE_RANK) {
            holder.getView(R.id.model_range).setVisibility(View.VISIBLE);
            holder.getView(R.id.tv_holder_name).setVisibility(View.VISIBLE);
            holder.getView(R.id.person_info_next).setVisibility(View.INVISIBLE);

            seekBar.setProgress(TextUtils.isEmpty(model.getValue()) ? 0 : (int) Double.parseDouble(model.getValue()));
        } else {
            holder.getView(R.id.model_range).setVisibility(View.GONE);
            holder.getView(R.id.tv_holder_name).setVisibility(View.VISIBLE);
            holder.getView(R.id.person_info_next).setVisibility(View.VISIBLE);
        }


        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mView.onRangeChange(progress);
                TextView t = holder.getView(R.id.tv_holder_name);
                t.setText(String.format("%d米", progress));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

//                if (mView.isSetPoint()) {
//                    seekBar.setEnabled(true);
//
//                } else {
//                    seekBar.setEnabled(false);
//                    ToastUtil.showToast("请先设置考勤点");
//                }


            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        if (!TextUtils.isEmpty(model.getValue())) {
            switch (model.getType()) {
                case EventCheckModel.EVENT_CHECK_TYPE_POINT:
                    holder.setText(R.id.tv_holder_name, model.getValue());
                    break;
                case EventCheckModel.EVENT_CHECK_TYPE_RANK:
                    holder.setText(R.id.tv_holder_name, model.getHintValue());
                    break;
                default:
                    holder.setText(R.id.tv_holder_name, model.getHintValue());
                    break;
            }
        } else {
            holder.setText(R.id.tv_holder_name, "去设置");
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mView.infoItemClick(model);
            }
        });
    }
}
